package com.example.smartplay.controller;


import com.example.smartplay.entity.Club;
import com.example.smartplay.entity.Clubmembership;
import com.example.smartplay.entity.Result;
import com.example.smartplay.mapper.ClubmembershipMapper;
import com.example.smartplay.service.ClubmembershipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-07-18
 */
@RestController
@RequestMapping("/clubmembership")
public class ClubmembershipController {
    @Autowired
    private ClubmembershipService clubmembershipService;
    @Autowired
    private ClubmembershipMapper clubmembershipMapper;
    //分页查询
    @GetMapping("/getClubmembership/{pageNum}/{pageSize}")
    public Result getClubmembership(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ){
        return clubmembershipService.getClubmembership(pageNum,pageSize);
    }

    //分页查询
    @GetMapping("/getClubmemberships/{pageNum}/{pageSize}")
    public Result getClubmemberships(
            @RequestParam(value = "keyword",required = false) String keyword,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ){ // 查询总记录数
        int total = clubmembershipMapper.countClubs();

        // 查询分页数据
        List<Clubmembership> Clubmembership = clubmembershipMapper.selectClubmembershipWithName(keyword, pageNum,pageSize);

        // 构建返回结果，包括分页数据和总记录数
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", Clubmembership);

        return Result.success(result);

    }




    //删除成员
    @DeleteMapping("{ids}")
    public Result delete(@PathVariable List<Integer> ids)
    {
        clubmembershipService.removeByIds(ids);
        return Result.success();
    }
}
